﻿using System;
using System.Windows.Forms;

namespace MyVocabulary.Popup
{
    public enum CustomMessageBoxButtons
    {
        OK,
        YesNo,
        Cancel
    }

    /// <summary>
    /// Used to fix the center parent problem of MessageBox
    /// </summary>
    public partial class CustomMessageBox : Form
    {      
        public CustomMessageBox(string text, string title, CustomMessageBoxButtons buttons)
        {
            InitializeComponent();
            lbText.Text = text;
            Text = title;
            switch (buttons)
            {
                case CustomMessageBoxButtons.OK:
                    {
                        btnOk.Visible = false;
                        btnCancel.Text = "OK";
                        btnCancel.DialogResult = DialogResult.Yes;
                        break;
                    }
                case CustomMessageBoxButtons.YesNo:
                    {
                        btnOk.Text = "Yes";
                        btnOk.DialogResult = DialogResult.Yes;
                        btnCancel.Text = "No";
                        btnCancel.DialogResult = DialogResult.No;       
                        break;
                    }
                case CustomMessageBoxButtons.Cancel:
                    {
                        btnCancel.Text = "Cancel";
                        btnCancel.DialogResult = DialogResult.Cancel;
                        btnOk.Visible = false;
                        break;
                    }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}